import 'package:flutter_plugin/base/controller/base_controller.dart';
import 'package:flutter_plugin/util/log_util.dart';

import '../../../net/api_respository.dart';
import '../../../net/base/NWMethod.dart';
import '../../../net/data/family_user_data.dart';
import '../../../net/http_url.dart';
import 'tab_home_state.dart';

class TabHomeLogic extends BaseController {
  final TabHomeState state = TabHomeState();

  @override
  void loadNet() {
    getBindList();
  }

  bool selectJudgeWithIndex(int index) {
    return state.selectedIndex.value == index;
  }

  @override
  void onInit() {
    super.onInit();
    state.scrollController.addListener(() {
      var value = state.scrollController.offset / state.scrollController.position.maxScrollExtent;
      state.scrollValue.value = 25 * value;
      LogD("addListener ${state.scrollValue.value}");
    });
  }

  void getBindList() {
    ApiRepository.instance.requestList<FamilyUserData>(HttpUrl.bindList, method: NWMethod.GET, success: (it) {
      LogD("getBindList $it");
      state.bindList.value = it;
    }, error: (e) {});
  }
}
